// jwt.js
const jwt = require("jsonwebtoken");
const jwtSecret = "your_jwt_secret_key_here"; // 请确保这个密钥是安全的

// 加密使用
const jwtEncryptionSign = (user) => {
  return jwt.sign({ username: user.userName, role: user.role }, jwtSecret, {
    expiresIn: "24h",
  });
};
// 解密
const jwtEncryptionVerify = (token) => {
  try {
    return jwt.verify(token, jwtSecret);
  } catch (err) {
    console.log(err);
    return null;
  }
};

module.exports = {
  jwtEncryptionSign,
  jwtEncryptionVerify,
  jwtSecret,
};
